
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/common/utils/utils.dart';
import 'package:flutter_base/common/widgets/widgets.dart';
import 'package:flutter_base/pages/addressbook/entitys/AddressBookEntity.dart';
import 'package:flutter_base/pages/home/widgets/search_bar.dart';

class AddressBookPage extends StatefulWidget {
  @override
  _AddressBookPageState createState() => _AddressBookPageState();
}

class _AddressBookPageState extends State<AddressBookPage> {
  List<AddressBookEntity> _list = [
    AddressBookEntity(name: '陈曙光', nickName: '曙光', company: ''),
    AddressBookEntity(name: '李晓光', nickName: '晓光', company: '科技工作部'),
    AddressBookEntity(name: '肖亚平', nickName: '亚平', company: '展览工作部'),
    AddressBookEntity(name: '向辉', nickName: '向辉', company: '展览工作部'),
    AddressBookEntity(name: '王丹心', nickName: '丹心', company: '资产财务部'),
    AddressBookEntity(name: '沈波', nickName: '沈波', company: '机经网工作部'),
    AddressBookEntity(name: '高立红', nickName: '立红', company: '国际合作部'),
    AddressBookEntity(name: '方杰', nickName: '方杰', company: '科技工作部'),
    AddressBookEntity(name: '姚之驹', nickName: '之驹', company: '行业发展部'),
    AddressBookEntity(name: '万道濮', nickName: '道濮', company: '统计与信息工作部'),
    AddressBookEntity(name: '王凌霄', nickName: '凌霄', company: '质量工作部'),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: ZtbAppBar(
        title: '通讯录',
        isBack: false,
      ),
      body: SafeArea(
          child: ListView.separated(
              shrinkWrap: true,
              itemBuilder: (BuildContext context, int index) {
                if (index == 0) {
                  return Container(
                    decoration: BoxDecoration(
                        gradient: LinearGradient(
                            colors: [Color(0x66000000), Colors.transparent],
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter)),
                    child: Container(
                      decoration: BoxDecoration(color: Colors.white),
                      child: SearchBar(
                        hideLeft: false,
                        defaultText: '',
                        hint: '搜索',
                        inputMargin: EdgeInsets.fromLTRB(8, 0, 8, 0),
                        leftButtonClick: () {
                          Navigator.pop(context);
                        },
                        onChanged: (val) {},
                      ),
                    ),
                  );
                }
                return Container(
                  color: Colors.white,
                  child: Row(
                    children: [
                      SizedBox(
                        width: zhiSetWidth(10),
                      ),
                      Container(
                        width: zhiSetWidth(50),
                        height: zhiSetHeight(45),
                        margin: EdgeInsets.all(zhiSetWidth(10)),
                        //边框设置
                        decoration: new BoxDecoration(
                          //背景
                          color: Colors.blueAccent,
                          //设置四周圆角 角度
                          borderRadius: BorderRadius.all(Radius.circular(6.0)),
                          //设置四周边框
                        ),
                        child: index == 4
                            ? ClipRRect(
                                borderRadius: BorderRadius.circular(6),
                                child: Image.network(
                                    "https://z3.ax1x.com/2021/07/05/Rht08s.jpg"),
                              )
                            : Center(
                                child: Text(
                                  _list[index].nickName,
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.w500),
                                ),
                              ),
                      ),
                      Expanded(
                        child: Container(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                _list[index].name,
                                style: TextStyle(fontSize: 18),
                              ),
                              Text(
                                _list[index].company,
                                style:
                                    TextStyle(fontSize: 14, color: Colors.grey),
                              ),
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return Container(
                  height: 0,
                  color: Colors.transparent,
                );
              },
              itemCount: _list.length)),
    );
  }
}
